<!--
 * @Author: 哈尔滨大拐 3181845089@qq.com
 * @Date: 2022-07-10 17:38:03
 * @LastEditors: 哈尔滨大拐 3181845089@qq.com
 * @LastEditTime: 2022-07-10 17:38:08
 * @FilePath: \mygit\实验\18-随机彩票history.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <button id="btn">生成彩票</button>
    <div id="result">

        <script>
            let btn = document.getElementById('btn');
            let result = document.getElementById('result');


            btn.addEventListener('click', function () {
                let arr = [];
                // 生成7个 [1-36] 随机数字
                for (let i = 0; i < 7; i++) {
                    let num = Math.floor(Math.random() * 36) + 1;
                    arr.push(num);
                }
                result.innerHTML = arr;

                history.pushState(arr, null);

            }, false);

            window.onpopstate = function (e) {
                result.innerHTML = e.state;
            }
        </script>
</body>

</html>